<template>
  <div id="evaluate">
    <top-bar :title="title"></top-bar>
    <div class="evaluate_bg">
      <div class="driver_box">
        <div class="driver_photo">
          <p>
            <img :src="driver_photoImg" />
          </p>
        </div>
        <div class="driver_car">
          <p>
            <span class="driver-name">{{getOrderInfoData?getOrderInfoData.driver_name:''}}</span>
            <span class="stars">
              <i :class="{'active':starsone}"></i>
              <i :class="{'active':starstwo}"></i>
              <i :class="{'active':starsthree}"></i>
              <i :class="{'active':starsfour}"></i>
              <i :class="{'active':starsfive}"></i>
            </span>
            <span class="dirver-score">{{getOrderInfoData?getOrderInfoData.driver_level:''}}</span>
          </p>
          <p>
            <span class="car-number">{{getOrderInfoData?getOrderInfoData.driver_number:''}}</span>
            <span class="car-brand">{{getOrderInfoData?getOrderInfoData.driver_carColor:''}} {{getOrderInfoData?getOrderInfoData.driver_car:''}}</span>
          </p>
        </div>
      </div>
      <div style="clear:both"></div>
      <div class="endOrdermoney">
        <p class="money_alt">￥{{getOrderInfoData?getOrderInfoData.order_amt:''}}</p>
        <p class="endOrdercharges" @click="chargesBtn">
          费用明细
          <md-icon name="wdqb-more" slot="left" class="quxiao_icon"></md-icon>
        </p>
      </div>
      <div class="driver_evaluate">
        <p class="evaluate_hd">我对司机的评价</p>
        <div class="starWrap">
          <img :src="level>index?stara:starb" v-for="(item,index) in levelList" :key="index" @click="getlevel(index)" />
          <p v-show="IsevaluateResult">{{evaluateResulttext}}</p>
        </div>
        <div v-show="IsevaluationList">
          <ul class="evaluationList">
            <li
              v-for="(item, index) in evaluationList"
              :key="index"
              @click="getevaluationList(index,item)"
              :class="{'evaluation-active':evaluationArr[index]}"
              ref="menuItem"
            >{{item}}</li>
          </ul>
        </div>
        <div style="clear:both"></div>
        <div class="complaints_input">
          <textarea placeholder="还想对司机说……" v-model="evaluationDescribe"></textarea>
        </div>
      </div>
      <p class="evaluationBtn" v-show="IsevaluationBtn" @click="evaluationBtn">提交评价</p>
    </div>
  </div>
</template>
<script>
import '@/assets/svgs/wdqb-more.svg';
import { Tabs, Icon, Field, InputItem, Toast, Dialog } from 'mand-mobile';
import TopBar from '@/components/TopBar';
import Loading from '@/components/loading';
import { mapGetters, mapActions, mapMutations } from 'vuex';
import { decryptByDESModeEBC, encryptByDESModeEBC } from '@/common/encrypt';
import http from '@/common/http';
var CryptoJS = require('crypto-js');
export default {
  components: {
    [Tabs.name]: Tabs,
    [Icon.name]: Icon,
    [TopBar.name]: TopBar,
    [Field.name]: Field,
    [Toast.name]: Toast,
    [Dialog.name]: Dialog,
    [InputItem.name]: InputItem
  },
  data() {
    return {
      title: '待评价',
      driver_photoImg: '',
      starsone: false,
      starstwo: false,
      starsthree: false,
      starsfour: false,
      starsfive: false,
      evaluationArr: [],
      evaluationnewArr: [],
      IsevaluationBtn: false,
      IsevaluateResult: false,
      IsevaluationList: false,
      evaluationDescribe: '',
      evaluateResulttext: '',
      level: 0,
      levelList: [0, 1, 2, 3, 4],
      stara: require('@/assets/imgs/xcxq_icon_xing_light@2x.png'), // 亮星星
      starb: require('@/assets/imgs/xcxq_icon_xing_dark@2x.png'), // 暗星星
      evaluationList: ['活地图认路准', '车内整洁', '驾驶平稳', '态度好服务棒', '准时出行', '沟通友好']
    };
  },
  mounted() {
    this.putevaluation();
    // 获取订单详情
    if (this.$route.query.orderno) {
      this.getOrderInfo(this.$route.query.orderno).then(() => {
        this.driver_photoImg = this.getOrderInfoData.driver_show
          ? this.getOrderInfoData.driver_show
          : require('@/assets/imgs/snyc_tx.png'); // 司机头像
        // 点亮司机评分星星
        var driverLevel = parseInt(this.getOrderInfoData.driver_level);
        if (driverLevel === 1) {
          this.starsone = true;
        } else if (driverLevel === 2) {
          this.starsone = true;
          this.starstwo = true;
        } else if (driverLevel === 3) {
          this.starsone = true;
          this.starstwo = true;
          this.starsthree = true;
        } else if (driverLevel === 4) {
          this.starsone = true;
          this.starstwo = true;
          this.starsthree = true;
          this.starsfour = true;
        } else if (driverLevel === 5) {
          this.starsone = true;
          this.starstwo = true;
          this.starsthree = true;
          this.starsfour = true;
          this.starsfive = true;
        }
      });
    } else {
      Dialog.alert({
        title: '提示',
        content: '获取不到订单号',
        confirmText: '确定'
      });
    }
  },
  methods: {
    ...mapActions(['getOrderInfo']),
    // 费用明细
    chargesBtn() {
      this.$router.push({
        name: 'ChargesDetails',
        query: {
          orderno: this.$route.query.orderno
        }
      });
    },
    // 获取评价星星
    getlevel(val) {
      if (val === 0) {
        this.evaluateResulttext = '非常不满意';
      } else if (val === 1) {
        this.evaluateResulttext = '不满意';
      } else if (val === 2) {
        this.evaluateResulttext = '一般';
      } else if (val === 3) {
        this.evaluateResulttext = '满意';
      } else if (val === 4) {
        this.evaluateResulttext = '非常满意';
      }
      this.IsevaluateResult = true;
      this.IsevaluationBtn = true;
      this.IsevaluationList = true;
      this.level = val + 1;
    },
    getevaluationList(index, item) {
      for (let i = 0; i < this.evaluationArr.length; i++) {
        if (i === index) {
          this.evaluationArr[index] ? this.evaluationArr.splice(index, 1, false) : this.evaluationArr.splice(index, 1, true);
          if (this.evaluationArr[index]) {
            this.evaluationnewArr.push(this.evaluationList[index]);
          } else {
            this.removeArr(item);
          }
        }
      }
      // console.log(this.evaluationnewArr);
    },
    queryIndexOf(item) {
      for (var i = 0; i < this.evaluationnewArr.length; i++) {
        if (this.evaluationnewArr[i] === item) {
          return i;
        }
      }
      return -1;
    },
    removeArr(item) {
      var index = this.queryIndexOf(item);
      if (index > -1) {
        this.evaluationnewArr.splice(index, 1);
      }
    },
    putevaluation() {
      for (let i = 0; i < this.evaluationList.length; i++) {
        this.evaluationArr.push(false);
      }
    },
    // 提交评价
    evaluationBtn() {
      var data = {
        order_no: this.$route.query.orderno,
        tagSta: this.level.toString(),
        tagPes: this.evaluationnewArr.join(','),
        tagCon: this.evaluationDescribe
      };
      console.log(data);
      Loading.show();
      http.post('pakj/common/orderEvaluate', data).then(res => {
        Loading.hide();
        if (res.data.code === '000000') {
          Dialog.alert({
            title: '提示',
            content: '评价成功',
            confirmText: '确定',
            onConfirm: () => {
              this.$router.push({
                name: 'SuccessEvaluate'
              });
            }
          });
        } else {
          Dialog.alert({
            title: '提示',
            content: res.data.msg,
            confirmText: '确定'
          });
        }
      });
    }
  },
  computed: {
    ...mapGetters(['getOrderInfoData'])
  }
};
</script>
<style lang="stylus" scoped>
p {
  display: block;
  margin-block-start: 0px;
  margin-block-end: 0px;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
}

#evaluate {
  height: 100vh;
  background-color: color-primary-background;
}

.evaluate_bg {
  background-color: #fff;
  height: 90vh;
  margin-top: 20px;
  padding-bottom: 20px;
}

.driver_box {
  margin: 20px 30px;
  padding-top: 30px;
}

.driver_photo {
  float: left;
}

.driver_photo p img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
}

.driver_car {
  float: left;
}

.driver_car p {
  margin-top: 10px;
  margin-left: 24px;
}

.driver-name {
  font-size: 30px;
  color: #333;
}

.stars {
  margin-left: 16px;
}

.stars i {
  display: inline-block;
  width: 24px;
  height: 22px;
  background: url('../../assets/imgs/xcxq_icon_xing_dark@2x.png') no-repeat center center;
  background-size: 24px 22px;
}

.stars i.active {
  background-image: url('../../assets/imgs/xcxq_icon_xing_light@2x.png');
}

.dirver-score {
  font-size: 26px;
  color: #666;
  margin-left: 16px;
}

.car-number {
  font-size: 26px;
  color: #666;
}

.car-brand {
  font-size: 26px;
  color: #999;
  margin-left: 16px;
}

.endOrdermoney {
  border-top: solid 1px #E0E0E0;
  text-align: center;
  padding-top: 68px;
  padding-bottom: 52px;
  margin-top: 20px;
}

.money_alt {
  font-size: 40px;
  color: #333;
}

.endOrdercharges {
  font-size: 24px;
  color: #999;
  margin-top: 10px;
}

.quxiao_icon {
  width: 24px;
  height: 24px;
  position: relative;
  top: 3px;
  margin-right: 8px;
}

.starWrap {
  width: 100%;
  text-align: center;
  margin: 40px auto;
}

.starWrap img {
  width: 68px;
  height: 62px;
  margin-left: 20px;
}

.starWrap p {
  font-size: 26px;
  color: #666;
  margin-top: 10px;
}

.driver_evaluate {
  position: relative;
  border-top: solid 1px #E0E0E0;
  margin: 0px 30px;
}

.evaluate_hd {
  background-color: #fff;
  font-size: 28px;
  color: #666;
  position: absolute;
  left: 50%;
  margin-left: -108px;
  top: -22px;
}

.evaluationList li {
  height: 72px;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  float: left;
  text-align: center;
  line-height: 72px;
  margin-left: 5%;
  margin-top: 20px;
  font-size: 28px;
  color: #666;
  padding: 0px 25px;
}

.evaluationList li.evaluation-active {
  border: 1px solid #ff6917;
  color: #ff6917;
}

.complaints_input {
  background-color: #fff;
  margin-top: 20px;
  padding: 0px 30px 20px 30px;
}

.complaints_input textarea {
  border: none;
  resize: none;
  width: 95%;
  height: 160px;
  background-color: #F8F8F8;
  padding: 10px 20px;
}

.evaluationBtn {
  background-color: #FF6917;
  margin: 76px 20px 0px 20px;
  height: 98px;
  line-height: 98px;
  font-size: 36px;
  color: #fff;
  text-align: center;
  border-radius: 10px;
}
</style>
